package com.xiaozhi;

import com.xiaozhi.aop.HelloService;
import com.xiaozhi.bean.Cat;
import com.xiaozhi.bean.Hello;
import com.xiaozhi.bean.Person;
import com.xiaozhi.config.AopOpenConfig;
import com.xiaozhi.config.MyConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 注解版Spring用法
 */
public class AnnotationMainTest {
	public static void main(String[] args) {
		// ==================import的两种方式==================
		ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MyConfig.class);
		HelloService helloService = applicationContext.getBean(HelloService.class);
		helloService.sayHello("tang");
//		Hello bean = applicationContext.getBean(Hello.class);
//		System.out.println("bean = " + bean);
//		System.out.println(bean.equals(applicationContext.getBean(Hello.class)));
//		Person person = applicationContext.getBean(Person.class);
//		System.out.println("person = " + person);
//		String[] names = applicationContext.getBeanDefinitionNames();
//		/**
//		 * 如果使用的是import方式导入的,那么这个bean的名字就是全类名
//		 * com.xiaozhi.bean.Person
//		 * tomcat
//		 */
//		for (String name : names) {
//			System.out.println(name);
//		}
		// ==================
//		Person person = applicationContext.getBean(Person.class);
//		System.out.println("person = " + person);
//		Cat cat1 = person.getCat();
//		Cat cat2 = person.getCat();
//		System.out.println(cat1 == cat2);//true
//		String[] names = applicationContext.getBeanDefinitionNames();
//		/**
//		 * 这里我们在配置文件中配置了@ComponentScan(value = "com.xiaozhi")
//		 * 进行扫描,可以看到这里的person和cat的名称
//		 * cat
//		 * person
//		 */
//		for (String name : names) {
//			System.out.println(name);
//		}
	}
}
